package sdk

import (
	"gim-server/sdk/tpns"
)

type PushOneAccountArgs struct {
	IsProd    bool
	AccessId  uint32
	SecretKey string
	Notify    bool
	Account   string
	Title     string
	Content   string
	BadgeType int
}

func PushOneAccount(args *PushOneAccountArgs) error {
	if args.AccessId == 0 {
		return nil
	}
	req := tpns.NewRequest(
		tpns.WithAudience(tpns.AudienceAccount),
		tpns.WithAccountList([]string{args.Account}),
		tpns.WithMessageType(func() tpns.MessageType {
			if args.Notify {
				return tpns.Notify
			} else {
				return tpns.Message
			}
		}()),
		tpns.WithTitle(args.Title),
		tpns.WithContent(args.Content),
		tpns.WithAndroidMessage(&tpns.AndroidMessage{
			BadgeType: args.BadgeType,
		}),
		tpns.WithIOSMessage(&tpns.IOSMessage{
			Aps: &tpns.IOSAps{
				BadgeType: args.BadgeType,
			},
		}),
		tpns.WithEnvironment(func() tpns.EnvironmentType {
			if !args.IsProd {
				return tpns.Develop
			} else {
				return tpns.Product
			}
		}()),
	)
	_, err := tpns.NewClient(tpns.ShanghaiHost, args.AccessId, args.SecretKey).Do(req)
	return err
}
